layui.define(['jquery','laytpl', 'layer'], function (exports) {
    var $ = layui.jquery,
        app = layui.data('app'),
        laytpl = layui.laytpl,
        toolbar = 'toolbar';
    tablebtn = {};

    /**
     * 初始化表头按钮
     */
    tablebtn.init = function (option) {
        var data=option;
        var functionTpl = option.temp.html();
        var functionHtml = '.tpl-button',
            button = '.layui-btn',
            head = '.layui-card-header',
            btnHtml;
        laytpl(functionTpl).render(data, function (html) {
            //拼接按钮
            if(option.type==1) {
                $(functionHtml).html(html);
                //给按钮绑定触发事件
                $(functionHtml).find(button).on({
                    click: function () {
                        var funThis = $(this);
                        var callback = {
                            elem: funThis,
                            event: funThis.attr('lay-event')
                        };
                        layui.event(toolbar, 'click(*)', callback);
                    }
                });
            }else{
                //直接返回html
                btnHtml=html;
            }
        });

        $(head).on('click', '.search_btn', function () {//查询按钮点击
            var oThis = $(this),
                params = {
                    elem: oThis,
                    event: oThis.attr('lay-event'),
                    data: oThis.attr('lay-data')
                };
            layui.event(toolbar, 'click(*)', params);
        });
        return btnHtml;
    };

    /**
     * 绑定表头按钮事件
     */
    tablebtn.buildOnClick = function (option) {
        //初始化化按钮
        // var function_option = {functions:$.extend(true,functionOption.functions,option.functions),row:functionOption.row};//$.extend(true,option.row,functionOption.row)};
        var btnHtml = this.init(option);
        //定义按钮事件
        var _option = {
            getEvent: function (data) {
                console.log(data);
                console.log("getevent");
            },//查看
            editEvent: function (data) {
                console.log(data);
                console.log("editevent");
            },//修改
            addEvent: function (data) {
                console.log(data);
                console.log("addevent");
            },//新增
            deleteEvent: function (data) {
                console.log(data);
                console.log("deleteevent");
            },//删除
            importEvent: function (data) {
                console.log("importevent");
            },//导入
            exportEvent: function (data) {
                console.log("exportevent");
            },//导出
            disableEvent: function (data) {
                console.log("disableevent");
            },//禁用
            enableEvent: function (data) {
                console.log("enableevent");
            },//启用
            searchEvent: function (data) {
                console.log("searchevent");
            },//查询
            lineMoreEvent: function (data) {
                console.log("lineevent");
            },//行更多
            confirmEvent:function(data){
                console.log("confirmEvent");
            },//确认
            auditEvent: function (data) {
                console.log("auditEvent");
            },//审核
            accessoryEvent: function (data) {
                console.log("accessoryEvent");
            },//附件管理
            generateBhd: function (data) {
                console.log("generateBhd");
            },//生成补货单
            cancelBh: function (data) {
                console.log("cancelBh");
            },//取消补货
            forwardingAgentEvent: function (data) {
                console.log("修改承运商类别");
            },
            searchinventoryEvent: function (data) {
                console.log("查看库存余量");
            },
            copyOrderEvent: function (data) {
                console.log("复制订单");
            },
            returnInventoryAgainEvent: function (data) {
                console.log("退单重报");
            },
            returninventoryEvent: function (data) {
                console.log("退单");
            },
            createNumberEvent: function (data) {
                console.log("创建波次");
            },
            orderSeparatedEvent: function (data) {
                console.log("订单拆单");
            },
            cancelSeparatedEvent: function (data) {
                console.log("取消拆单");
            },
            allocationEvent: function (data) {
                console.log("分配");
            },
            cancelAllocationEvent: function (data) {
                console.log("取消分配");
            },
            pickingEvent: function (data) {
                console.log("拣货");
            },
            deductionAuditEvent: function (data) {
                console.log("抵扣审核");
            },
            borrowCargoEvent: function (data) {
                console.log("借货完结");
            },
            packingEvent: function (data) {
                console.log("装箱");
            },
            cancelPackingEvent: function (data) {
                console.log("取消装箱");
            },
            searchSeparatedDetailEvent: function (data) {
                console.log("查看拆单明细");
            },
            searchAllocationDetailEvent: function (data) {
                console.log("查看分配明细");
            },
            searchPackingDetailEvent: function (data) {
                console.log("查看装箱明细");
            },
            signEvent: function (data) {
                console.log("标记");
            },
            printExpressSingleEvent: function (data) {
                console.log("打印快递面单");
            },
            printBoxLabelEvent: function (data) {
                console.log("打印箱标签");
            },
            printEvent:function(data){
                console.log("printEvent");
            },//通用打印
            PO_AddEvent:function(data){
                console.log("PO_AddEvent");
            },//预期到过通知单PO提取
            generateEvent:function(data){
                console.log("generateEvent");
            },//生成质检单
            AsnEvent:function(data){
                console.log("AsnEvent");
            },//查看ASN收货
            searchBhEvent:function(data){
                console.log("searchBhEvent");
            },//查看补货任务
            scsjrwEvent:function(data){
                console.log("scsjrwEvent");
            },//生成质检任务
            peizhiOrderEvent:function(data){
                console.log("peizhiOrderEvent");
            },//配置订单
            zjKwEvent:function(data){
                console.log("zjKwEvent");
            },//暂存集货
            assistEvent:function(data){
                console.log("assistEvent");
            },//协助称重
            forwardingEvent:function(data){
                console.log("forwardingEvent");
            },//发运
            createEvent:function(data){
                console.log("createEvent");
            },//创建装车单
            editLocation:function(data){
                console.log("editLocation");
            },//编辑库位
            temporaryBfhEvent: function (data) {
                console.log("temporaryBfhEvent");
            },//标记暂不发货
            BatchPrintBoxLabelEvent: function (data) {
                console.log("BatchPrintBoxLabelEvent");
            },//批量打印箱标签
            batchPrintExpressSingleEvent: function (data) {
                console.log("batchPrintExpressSingleEvent");
            },//批量打印快递面单
            kuweizuEvent: function (data) {
                console.log("kuweizuEvent");
            },//绑定库位组
            yujianEvent: function (data) {
                console.log("yujianEvent");
            },//预检
            xiafaRwEvent: function (data) {
                console.log("xiafaRwEvent");
            },///*盘点任务下发*/
            closeRwEvent: function (data) {
                console.log("closeRwEvent");
            },/*关闭盘点*/
            createStockTzEvent: function (data) {
                console.log("createStockTzEvent");
            },/*生成库存调整单*/
            panDianEvent: function (data) {
                console.log("panDianEvent");
            },/*库存盘点*/
            createRwEvent: function (data) {
                console.log("createRwEvent");
            },/*生成盘点任务*/
            cancelRw: function (data) {
                console.log("cancelRw");
            },/*取消盘点任务*/
            Stockthawing: function (data) {
                console.log("Stockthawing");
            },/*库存解冻*/
            Warehousing: function (data) {
                console.log("Warehousing");
            },/*入库*/
            getlibrary: function (data) {
                console.log("getlibrary");
            },/*出库*/
            figureOut: function (data) {
            console.log("figureOut");
            },/*出库异常处理*/

        }

        _option = $.extend(true, _option, option.event);
        if (_option) {
            layui.onevent(toolbar, 'click', function (data) {
                var event = data.event;
                switch (event) {
                    case 'getEvent':
                        _option.getEvent(data);
                        break;
                    case 'addEvent':
                        _option.addEvent(data);
                        break;
                    case 'editEvent':
                        _option.editEvent(data);
                        break;
                    case 'deleteEvent':
                        _option.deleteEvent(data);
                        break;
                    case 'importEvent':
                        _option.importEvent(data);
                        break;
                    case 'exportEvent':
                        _option.exportEvent(data);
                        break;
                    case 'disableEvent':
                        _option.disableEvent(data);
                        break;
                    case 'enableEvent':
                        _option.enableEvent(data);
                        break;
                    case 'searchEvent':
                        _option.searchEvent(data);
                        break;
                    case 'lineMoreEvent':
                        _option.lineMoreEvent(data);
                        break;
                    case 'confirmEvent':
                        _option.confirmEvent(data);
                        break;
                    case 'auditEvent':
                        _option.auditEvent(data);
                        break;
                    case 'accessoryEvent':
                        _option.accessoryEvent(data);
                        break;
                    case 'generateBhd':
                        _option.generateBhd(data);
                        break;
                    case 'cancelBh':
                        _option.cancelBh(data);
                        break;
                    case 'forwardingAgentEvent':
                        _option.forwardingAgentEvent(data);
                        break;
                    case 'searchinventoryEvent':
                        _option.searchinventoryEvent(data);
                        break;
                    case 'copyOrderEvent':
                        _option.copyOrderEvent(data);
                        break;
                    case 'returnInventoryAgainEvent':
                        _option.returnInventoryAgainEvent(data);
                        break;
                    case 'returninventoryEvent':
                        _option.returninventoryEvent(data);
                        break;
                    case 'createNumberEvent':
                        _option.createNumberEvent(data);
                        break;
                    case 'orderSeparatedEvent':
                        _option.orderSeparatedEvent(data);
                        break;
                    case 'cancelSeparatedEvent':
                        _option.cancelSeparatedEvent(data);
                        break;
                    case 'allocationEvent':
                        _option.allocationEvent(data);
                        break;
                    case 'cancelAllocationEvent':
                        _option.cancelAllocationEvent(data);
                        break;
                    case 'pickingEvent':
                        _option.pickingEvent(data);
                        break;
                    case 'deductionAuditEvent':
                        _option.deductionAuditEvent(data);
                        break;
                    case 'borrowCargoEvent':
                        _option.borrowCargoEvent(data);
                        break;
                    case 'packingEvent':
                        _option.packingEvent(data);
                        break;
                    case 'cancelPackingEvent':
                        _option.cancelPackingEvent(data);
                        break;
                    case 'searchSeparatedDetailEvent':
                        _option.searchSeparatedDetailEvent(data);
                        break;
                    case 'searchAllocationDetailEvent':
                        _option.searchAllocationDetailEvent(data);
                        break;
                    case 'searchPackingDetailEvent':
                        _option.searchPackingDetailEvent(data);
                        break;
                    case 'signEvent':
                        _option.signEvent(data);
                        break;
                    case 'printExpressSingleEvent':
                        _option.printExpressSingleEvent(data);
                        break;
                    case 'printBoxLabelEvent':
                        _option.printBoxLabelEvent(data);
                        break;
                    case 'printEvent':
                        _option.printEvent(data);
                        break;
                    case 'PO_AddEvent':
                        _option.PO_AddEvent(data);
                        break;
                    case 'generateEvent':
                        _option.generateEvent(data);
                        break;
                    case 'AsnEvent':
                        _option.AsnEvent(data);
                        break;
                    case 'searchBhEvent':
                        _option.searchBhEvent(data);
                        break;
                    case 'scsjrwEvent':
                        _option.scsjrwEvent(data);
                        break;
                    case 'peizhiOrderEvent':
                        _option.peizhiOrderEvent(data);
                        break;
                    case 'zjKwEvent':
                        _option.zjKwEvent(data);
                        break;
                    case 'assistEvent':
                        _option.assistEvent(data);
                        break;
                    case 'forwardingEvent':
                        _option.forwardingEvent(data);
                        break;
                    case 'createEvent':
                        _option.createEvent(data);
                        break;
                    case 'editLocation':
                        _option.editLocation(data);
                        break;
                    case 'temporaryBfhEvent':
                        _option.temporaryBfhEvent(data);
                        break;
                    case 'BatchPrintBoxLabelEvent':
                        _option.BatchPrintBoxLabelEvent(data);
                        break;
                    case 'batchPrintExpressSingleEvent':
                        _option.batchPrintExpressSingleEvent(data);
                        break;
                    case 'kuweizuEvent':
                        _option.kuweizuEvent(data);
                        break;
                    case 'yujianEvent':
                        _option.yujianEvent(data);
                        break;
                    case 'xiafaRwEvent':
                        _option.xiafaRwEvent(data);
                        break;
                    case 'closeRwEvent':
                        _option.closeRwEvent(data);
                        break;
                    case 'createStockTzEvent':
                        _option.createStockTzEvent(data);
                        break;
                    case 'panDianEvent':
                        _option.panDianEvent(data);
                        break;
                    case 'createRwEvent':
                        _option.createRwEvent(data);
                        break;
                    case 'cancelRw':
                        _option.cancelRw(data);
                        break;
                    case 'Stockthawing':
                        _option.Stockthawing(data);
                        break;
                    case 'Warehousing':
                        _option.Warehousing(data);
                        break;
                    case 'getlibrary':
                        _option.getlibrary(data);
                        break;
                    case 'figureOut':
                        _option.figureOut(data);
                        break;

                }
            });
        }
        return btnHtml;
    }
    tablebtn.tooltipster = function(option){
        var _option = {
            // contentCloning: true,
            interactive: true,
            trigger: 'click',
            side: 'left',
            theme: 'tooltipster-shadow'
        }
        _option = $.extend(true,_option,option);
        option.elem.tooltipster(_option);
    }
    /*    function createBtn(data){
     vat btnHtml='<div class="layui-inline">';
     if(data.functions!=null && data.functions!=undefined){
     if(data.row!=undefined && data.row!=null){
     btnHtml += '';
     }else {
     btnHtml += '';
     }
     }
     }*/
    exports("tablebutton", tablebtn);
});
